import pymysql


class Db:
    def __init__(self) -> None:
        self.conn = pymysql.connect(host='localhost', port=3306, user='root',
                                    password='111222', db='p9_10_7', cursorclass=pymysql.cursors.DictCursor)
        self.cursor = self.conn.cursor()

    def find(self, sql):
        self.cursor.execute(sql)
        res = self.cursor.fetchone()
        return res

    def find_all(self, sql):
        self.cursor.execute(sql)
        res = self.cursor.fetchall()
        return res

    def update(self, sql):
        self.cursor.execute(sql)

    def commit(self):
        self.conn.commit()

    def rollback(self):
        self.conn.rollback()


db = Db()